package com.alipay.benchmark;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Created by crazytime on 14-3-1.
 */
public class SingleLinkedBlockQueue {
    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<Long> queue=new LinkedBlockingQueue<Long>(10000);
          long ITERATIONS = 1000L * 1000L * 100L;
        long start=System.nanoTime();
        for(long i=0;i<ITERATIONS;i++){
            queue.put(new Long(1));
            queue.take();
        }
        long duration=System.nanoTime()-start;
        long ops = (ITERATIONS * 1000L * 1000L * 1000L) / duration;
        System.out.format("ops/sec    = %,d\n", ops);
        System.out.format("latency ns = %.3f%n", duration / (float)(ITERATIONS) );
    }
}
